<?php
/**
 * Description of user
 *
 * @author Henson
 */
class User extends Base{
	
	private $userTable = "tbl_user";
	
	private $vipTable = "tbl_vip_members";
	
	public function insertUser($insertArr)
	{
		$insertArr['insert_time'] = time();
		$insertArr['del'] = '0';
		return $this->db->insert($insertArr, $this->userTable);
	}
	
	public function updateUser($updateArr, $uid)
	{
		$updateArr['update_time'] = time();
		$where = " where id=".$uid;
		return $this->db->update($updateArr, $this->userTable, $where);
	}
	
	public function getUserByEmail($email)
	{
		$sql = "select * from {$this->userTable} where email='".$email."' limit 1";
		return $this->db->loadRow($sql);
	}
	
	public function getUserByUid($uid)
	{
		$sql = "select * from {$this->userTable} where id='".$uid."' limit 1";
		return $this->db->loadRow($sql);
	}
	
	public function checkVip($encorecard)
	{
		$sql = "select count(id) as total from {$this->vipTable} where encorecard=".$encorecard." limit 1";
		$row = $this->db->loadRow($sql);
		if($row['total'] > 0)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	
	public function getUserTotal()
	{
		$where = "where del='0'";
		return $this->getTotalNum($this->userTable, $where);
	}
	
	public function getUserList($where, $orderBy='', $limit='')
	{
		$sql = "select * from {$this->userTable} {$where} {$orderBy} {$limit}";
		$this->db->setQuery($sql);
		return $this->db->loadAssocList();
	}
	
	public  function dealUser($user)
	{
		global $_CFG;
		@$user['insert_time_list'] = date("Y-m-d H:i", $user['insert_time']);
		@$user['title'] = $_CFG['userTitle'][$user['title']];
		@$user['country'] = $_CFG['country'][$user['country']];
		return $user;
	}
}
?>